﻿using LPPA.Facturacion.BusinessLayer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LPPA.Facturacion.UI.Views.Medidores
{
	public partial class MedidoresHome : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
            if(!Page.IsPostBack)
                LoadInitData();

            gvMedidores.SelectedIndexChanged += gvMedidores_SelectedIndexChanged;
            btnBuscarMedidor.ServerClick += btnBuscarMedidor_ServerClick;
		}

        void btnBuscarMedidor_ServerClick(object sender, EventArgs e)
        {
            gvMedidores.DataSource = MedidorService.GetAllByFilter(txtBuscarMedidor.Value);
            gvMedidores.DataBind();

        }

        private void LoadInitData()
        {
            //Grid View
            gvMedidores.DataSource = MedidorService.GetAll();
            gvMedidores.DataBind();

        }

        void gvMedidores_SelectedIndexChanged(object sender, EventArgs e)
        {
            var medidorSelectedId = gvMedidores.SelectedRow.Cells[1].Text;

            Response.Redirect(ResolveUrl("/Views/Medidores/Medidor.aspx?Id=" + medidorSelectedId));
        }
	}
}